package com.kye.express.business.jd.shop.viewbinder;

import android.databinding.DataBindingUtil;
import android.support.annotation.NonNull;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;

import com.kye.express.R;
import com.kye.express.business.jd.shop.model.JDIntegralModel;
import com.kye.express.databinding.ItemJdShopIntegralBinding;
import com.kye.express.utils.StringUtils;

import me.drakeet.multitype.ItemViewBinder;

/**
 * @author : Joe
 * @version : 1.0
 * @editor : Joe
 * @created : 29/01/2018
 * @updated : 29/01/2018
 * @description : <Description>
 * @update_reason : <UpdateReason>
 */

public class JDInegralViewBinder extends ItemViewBinder<JDIntegralModel, JDInegralViewBinder.ViewHolder> {

    @NonNull
    @Override
    protected ViewHolder onCreateViewHolder(@NonNull LayoutInflater inflater, @NonNull ViewGroup parent) {
        View view = inflater.inflate(R.layout.item_jd_shop_integral, parent, false);
        return new ViewHolder(view);
    }

    @Override
    protected void onBindViewHolder(@NonNull ViewHolder holder, @NonNull JDIntegralModel item) {
        holder.bindData(item);
    }

    public class ViewHolder extends RecyclerView.ViewHolder {

        private ItemJdShopIntegralBinding binding;
        private JDIntegralModel item;

        public ViewHolder(View itemView) {
            super(itemView);
            binding = DataBindingUtil.bind(itemView);
        }

        public void bindData(JDIntegralModel item) {
            this.item = item;
            binding.setData(item);
            // 是否跨越用户 1:是
            // 可用积分
            int kyeUser = item.getIntegralUserBean().getKyeUser();
            switch (kyeUser) {
                case 0:
                    Double systemIntegral = Double.valueOf(item.getIntegralUserBean().getSystemIntegral());
                    binding.integralAvailable.setText(StringUtils.getIntegralFormat(systemIntegral));
                    break;
                case 1:
                    Double jdIntegral = Double.valueOf(item.getIntegralUserBean().getJdIntegral());
                    binding.integralAvailable.setText(StringUtils.getIntegralFormat(jdIntegral));
                    break;
            }
            // 当天可用积分
            Double trueAvailableIntegral = Double.valueOf(item.getIntegralUserBean().getTrueAvailableIntegral());
            binding.integralAvailableToday.setText(StringUtils.getIntegralFormat(trueAvailableIntegral));
        }
    }
}
